package com.joysuch.wwyt.attendant.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.joysuch.wwyt.attendant.bean.AttendantRecordProcessAppReqBean;
import com.joysuch.wwyt.attendant.bean.AttendantRecordProcessBean;
import com.joysuch.wwyt.attendant.bean.vo.AttendantStatisticsAreaVo;
import com.joysuch.wwyt.attendant.bean.vo.AttendantStatisticsUserVo;
import com.joysuch.wwyt.attendant.entity.AttendantRecordProcess;
import com.joysuch.wwyt.attendant.enums.ProcessStatusEnum;
import com.joysuch.wwyt.attendant.mapper.AttendantRecordProcessMapper;
import com.joysuch.wwyt.attendant.service.AttendantRecordProcessService;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.Date;
import java.util.List;

/**
 * @author xsx
 * @version 1.0
 * @date 2023/2/16 17:50
 */
@Service
@Transactional(rollbackFor = Exception.class)
public class AttendantRecordProcessServiceImpl extends ServiceImpl<AttendantRecordProcessMapper, AttendantRecordProcess> implements AttendantRecordProcessService {


    @Override
    public AttendantRecordProcess getAttendantRecordProcess(Long dataSourceId, String processInstanceId) {
        AttendantRecordProcess attendantRecordProcess = baseMapper.getAttendantRecordProcess(dataSourceId, processInstanceId);
        return attendantRecordProcess;
    }

    @Override
    public void saveProcess(AttendantRecordProcessAppReqBean bean) {
        AttendantRecordProcess process = new AttendantRecordProcess();
        BeanUtils.copyProperties(bean, process);
        process.setCreateTime(new Date());
        process.setProcessStatus(ProcessStatusEnum.UNFINISHED.getValue());
        process.setAttendantRecordId(bean.getDataSourceId());
        baseMapper.insert(process);
    }

    @Override
    public List<AttendantRecordProcessBean> selectProcessByPlanId(Long id) {
        List<AttendantRecordProcessBean> list = baseMapper.selectProcessByPlanId(id);
        return list;
    }

    @Override
    public long countByStatus(String status) {
        return baseMapper.countByStatus(status);
    }

    @Override
    public List<AttendantStatisticsUserVo> findStatisticsUserList(List<Long> recordUserIds) {
        return baseMapper.findStatisticsUserList(recordUserIds);
    }

    @Override
    public List<AttendantStatisticsAreaVo> findStatisticsAreaList(List<Long> recordAreaIds) {
        return baseMapper.findStatisticsAreaList(recordAreaIds);
    }
}
